home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / misc / emu / Apex-src.lha / XPL68K.DOC < prev    next >
Text File  |  2001-09-30  |  8KB  |  248 lines

  1. XPL68K.DOC    APR-12-87
  2.  
  3. This is a collection of notes related to running XPL, V5.7 on the 68000
  4. in 32-bit mode.
  5.  
  6.  
  7. REGISTER USAGE
  8.  
  9. The top of the working stack is kept in data registers and is called a
  10. pseudo stack. The compiler keeps track of the pseudo stack pointer and
  11. generates the appropriate data register numbers. When this pseudo stack
  12. overflows, the compiler will generate code which pushes these registers
  13. onto the real stack.
  14.  
  15. The registers are used as follows:
  16.     D0    -  Scratch
  17.     D1    -  Pseudo stack  (start)
  18.     D2    -    |
  19.     D3    -    |
  20.     D4    -    |
  21.     D5    -  Pseudo stack  (end)
  22.     D6    -  Register variable (if used)
  23.     D7    -  Register variable (if used)
  24.  
  25.     A0    -  Frame pointer, level 0
  26.     A1    -    |
  27.     A2    -    |
  28.     A3    -    |
  29.     A4    -  Frame pointer, level 4
  30.     A5  -  Heap pointer
  31.     A6    -  Scratch
  32.     A7    -  Stack pointer (SP)
  33.  
  34. All XPL variables and arrays are stored in a data structure called a
  35. heap. A heap is similar to a stack but it grows upward in memory, and it
  36. is less restrictive about how data is "pushed" onto it. In addition to a
  37. heap pointer there are frame pointers which point to the base address of
  38. variables corresponding to each level of (static) procedure nesting.
  39.  
  40.  
  41. STRING TERMINATION
  42.  
  43. The convention for terminating strings has been changed. Strings are now
  44. terminated with a zero byte instead of having the most significant bit
  45. set on the last character. This allows using the 128 additional char-
  46. acters defined by the (IBM) extended ASCII set. This also makes it
  47. simpler to perform string operations such as concatenation.
  48.  
  49.  
  50. SHIFT OPERATORS
  51.  
  52. Shift operators have been added to partially compensate for the slower
  53. 32-bit multiply and divide routines (shifts may be used to replace most
  54. multiplications and divisions by powers of 2). The general form of the
  55. shift expressions are:
  56.  
  57.     EXPR << EXPR     or    EXPR >> EXPR
  58.  
  59. EXPR is an integer sub-expression (a 32-bit value), "<<" indicates shift
  60. to the left, and ">>" means shift to the right. The sub-expression to the
  61. right of the shift operator specifies the number of bits to shift. This
  62. should be a positive value in the range 0 through 63. Shifting more than
  63. 31 bits will alway give a zero result. Here are some examples:
  64.  
  65.     1 << 1        = 2
  66.     $30 << 2    = $C0
  67.     $50 >> 4    = $05
  68.     $FFFFFF5A >> 4    = $0FFFFFF5
  69.  
  70. The shift operator's precedence is between the unary operators, and the
  71. multiplication and division operators. Thus the following pairs of
  72. expressions are equivalent:
  73.  
  74.     -1 >>16 *2     =     (-1 >>16) *2    = $1FFFE
  75.     2+1 <<8        =     2 + (1 <<8)    = $102
  76.  
  77.  
  78. MORE OPERATORS
  79.  
  80. An "exclusive or" operator has been added. It is indicated by the
  81. vertical bar symbol (|). "Exclusive or" has the same precedence as the
  82. "or" operator (!).
  83.  
  84. The tilde (~) can be used to indicate the ones complement operation. It
  85. is exactly the same as the existing 'NOT' operator; it is just a more
  86. compact notation.
  87.  
  88. For example:
  89.  
  90.     A | B    =    A&~B ! ~A&B    =    (A & 'NOT'B) ! ('NOT'A & B)
  91.  
  92.  
  93. REGISTER VARIABLES
  94.  
  95. A procedure can run as much as twice as fast if its variables are in
  96. registers instead of memory. Thus the 'REGISTER' declaration:
  97.  
  98.     'REGISTER' 'INTEGER' A, B;
  99.  
  100. This declares A and B as integers which are to be kept in registers.
  101.  
  102. The registers are taken from the top of the pseudo stack. You can have
  103. five of them in scope at one time, but be aware that this may actually
  104. slow things down since the pseudo stack will need to be pushed and pulled
  105. more often.
  106.  
  107. The only other restriction is that you can't, of course, get the address
  108. of a register variable, as with:
  109.  
  110.     X:= 'ADDR' A;
  111.  
  112. Register variables can receive arguments, and can be used for addresses
  113. and reals, for example:
  114.  
  115.     'REGISTER' 'ADDR' PORT;
  116.     'REGISTER' 'REAL' ANGLE, DISTANCE;
  117.  
  118.  
  119.  
  120. INTERCHANGEABLE CODE
  121.  
  122. XPL code and assembly code may be mixed in a much more straightforward
  123. manner than before.
  124.  
  125. XPL code can run in either user or supervisor mode.
  126.  
  127. XPL code can be called from assembly language code. The XPL code only
  128. requires that in addition to a stack, pointed to by A7, a heap, pointed
  129. to by A5, must be provided. Separately compiled XPL programs can be
  130. called as subroutines from either XPL or assembly language.
  131.  
  132. D0 and A6 are used as scratch registers by XPL code and are not saved and
  133. restored.
  134.  
  135. Procedures, intrinsics, and externals are all handled the same way. They
  136. all receive arguments on the heap. For example, if the heap pointer, A5,
  137. is at location 10000, then the call FROG(A, B, C) will copy the arguments
  138. into these locations:
  139.  
  140.     A5 -->    10000: A
  141.         10004: B
  142.         10008: C
  143.  
  144. Any procedure, intrinsic, or external which is used as a function will
  145. return its value in D0.
  146.  
  147. The result is that a program calling a subroutine need not know if the
  148. subroutine was written in XPL or assembly language.
  149.  
  150.  
  151. OTHER ITEMS
  152.  
  153. The order of the arguments in the BLIT intrinsic has changed. Before the
  154. order was: BLIT(TO, FROM, SIZE), now it is: BLIT(FROM, TO, SIZE).
  155.  
  156. The compiler now recognizes eight significant characters, instead of just
  157. six, in variable and procedure names, etc. The symbol table size has
  158. increased from 254 to 1000 entries. The number of 'QUIT's allowed in a
  159. 'LOOP' has increased from 10 to 100. The number of real constants allowed
  160. in scope at one time has increased from 25 to 100.
  161.  
  162. A "sync" byte may be generated in strings and byte arrays to keep opcodes
  163. and the heap on even-byte boundaries. Beware that consecutive array
  164. RESERVEs will have sync bytes between them if they are not an even number
  165. of bytes long.
  166.  
  167. The compiled code is position-independent except for multi-dimensional
  168. constant arrays.
  169.  
  170.  
  171. INCOMPATABILITIES WITH 6502 XPL
  172.  
  173. 68K XPL terminates strings with a zero byte; 6502 strings are terminated
  174. by setting the MSB on the last character.
  175.  
  176. 6502 XPL stores low byte, high byte in memory; the 68000 stores high
  177. byte, low byte.
  178.  
  179. 68K XPL is limited to 5 levels of static nesting (versus 8 for 6502).
  180. This is only a minor problem since most programs only use 2 or 3 levels.
  181. The compiler uses all 5 levels, but forward procedure declarations could
  182. reduce this.
  183.  
  184. Consecutive RESERVEs can have sync bytes between them as described above.
  185.  
  186. If you restart a program on the 68000 a RESERVE will clobber the previous
  187. contents of the first four bytes in the array.
  188.  
  189. Beware! Even reading an invalid location in a 2-dimentional (or more)
  190. array can cause a 68000 address-error trap to occur.
  191.  
  192. The 68000 version is missing some intrinsics: TRAP=17, GETERR=22, MOD=58,
  193. PEEK=66 and POKE=67. The floating point intrinsics are currently
  194. accomplished by XPL routines which are declared as linked procedures (and
  195. functions).
  196.  
  197. The compiled code cannot exceed 32767 bytes. This might be a permanent
  198. restriction since larger programs ought to be broken up into modules
  199. anyway.
  200.  
  201. With the 32-bit version, there are the following incompatabilities:
  202.  
  203.     Integer array's RESERVE size -- there are now 4 bytes in
  204.     an integer (or address) not just 2. 
  205.  
  206.     Now there are 8 bytes in a real not just 6.
  207.  
  208.     Watch out for code that assumes 16-bit integers such as
  209.     fitting a 128-integer array into one block on the disk.
  210.  
  211.     HEXOUT displays 8 digits instead of 4.
  212.  
  213.     The value $FFFF is now 65535 not -1, etc.
  214.  
  215. Watch out for code that requires line feeds. Now the last character on a
  216. line is a carriage return. Linefeeds have been banished from all text
  217. files.
  218.  
  219. The reserved word 'CHAR' has been dropped; use 'ADDR' instead. Also use
  220. 'OTHER' in place of 'ELSE' in case statements. 
  221.  
  222. HEAP STATE BEFORE AND AFTER A PROCEDURE CALL
  223.  
  224.  
  225.  
  226.         +---+---+---+---+ - - - - - - - - - - -
  227. initial HP -->    | 1st        |    \        \  <-- frame pointer
  228.         +---+---+---+---+     |         |    (Alev)
  229.         | 2nd        |     |-- arguments     |
  230.         +---+---+---+---+     |         |
  231.         | 3rd        |    /         |
  232.         +---+---+---+---+             |-- local variables
  233.         |        |             |
  234.         +---+---+---+---+             |
  235.         |        |             |
  236.         +---+---+---+---+             |
  237.         |        |             |
  238.         +---+---+---+---+             |
  239.         |        |            /
  240.         +---+---+---+---+ - - - - - - - - - - -
  241.         |        |  <-- final HP
  242.         +---+---+---+---+
  243.  
  244.         addresses increase
  245.          going down    |
  246.                 |
  247.                 V
  248. +---+ -